import java.util.Scanner;

public class Main {
    public static String reverse(String str,int begin,int end){
        char ch[] = str.toCharArray();
        while(begin < end){
            char tmp = ch[begin];
            ch[begin] = ch[end];
            ch[end] = tmp;
            begin++;
            end--;
        }
        return String.copyValueOf(ch);
    }

    public static String reverseK(String str,int k){
        if(str == null || k <= 0 || k >= str.length()){
            return null;
        }
        str = reverse(str,0,k-1);
        str = reverse(str,k,str.length()-1);
        str = reverse(str,0,str.length()-1);

        return str;
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要翻转的字符串：");
        System.out.println();
        String str = scanner.next();
        System.out.print("请输入翻转的开始索引：");
        System.out.println();
        int k = scanner.nextInt();
        String ret = reverseK(str,k);
        System.out.println("翻转后结果为：");
        System.out.println(ret);
    }
}